﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace CoreRay
{
    public class ScenegraphView : SceneView
    {
        public ScenegraphView()
        {
            this.RootNode = new SceneViewNode("World", this);
        }

        public override string Name
        {
            get 
            {
                return "Scenegraph";
            }
        }

        public override void OnSceneObjectAdded(SceneObject parentObject, SceneObject sceneObject)
        {
            // Find the parent node
            var parentNode = this.FindSceneViewNode(parentObject);

            // Add the scene object
            if (parentNode != null)
            {
                parentNode.ChildrenNodes.Add(new SceneViewNode(sceneObject.Name, this, sceneObject, parentNode));
            }
        }

        public override void OnSceneObjectDeleted(SceneObject sceneObject)
        {
            // Find the node
            var node = this.FindSceneViewNode(sceneObject);

            // Remove the node
            if (node != null)
            {
                node.ParentNode.ChildrenNodes.Remove(node);
            }
        }
    }
}
